package com.pine.manager.pineframework;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.pine.dao.pineframework.entity.SysApprovalApplication;
import com.pine.dao.pineframework.mapper.SysApprovalApplicationMapper;
import com.pine.manager.core.BaseManager;
import com.pine.manager.pineframework.bo.SysApprovalApplicationBo;
import com.pine.manager.pineframework.convertors.SysApprovalApplicationConvertor;
import com.pine.manager.pineframework.query.SysApprovalApplicationQuery;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 系统审批申请表 管理类
 * </p>
 *
 * @author pine manage
 * @since 2024-10-31
 */
@Component
public class SysApprovalApplicationManager extends BaseManager<SysApprovalApplicationMapper, SysApprovalApplication, Long, SysApprovalApplicationBo, SysApprovalApplicationQuery, SysApprovalApplicationConvertor> {

    @Resource
    private SysApprovalApplicationConvertor sysApprovalApplicationConvertor;

    @Override
    public LambdaQueryWrapper<SysApprovalApplication> encapsulateQueryWrapper(SysApprovalApplicationQuery query) {
        LambdaQueryWrapper<SysApprovalApplication> queryWrapper = super.encapsulateQueryWrapper(query);
        if (query == null) {
            return queryWrapper;
        }

        // 组装查询条件
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getApprovalId()), SysApprovalApplication::getApprovalId, query.getApprovalId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getName()), SysApprovalApplication::getName, query.getName());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getType()), SysApprovalApplication::getType, query.getType());
        queryWrapper.like(ObjectUtils.isNotEmpty(query.getContent()), SysApprovalApplication::getContent, query.getContent());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getAttachmentUrl()), SysApprovalApplication::getAttachmentUrl, query.getAttachmentUrl());
        queryWrapper.in(ObjectUtils.isNotEmpty(query.getStatus()), SysApprovalApplication::getStatus, query.getStatus());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getUpdateTimeStart()), SysApprovalApplication::getUpdateTime, query.getUpdateTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getUpdateTimeEnd()), SysApprovalApplication::getUpdateTime, query.getUpdateTimeEnd());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCreateUserId()), SysApprovalApplication::getCreateUserId, query.getCreateUserId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCreateUsername()), SysApprovalApplication::getCreateUsername, query.getCreateUsername());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getUpdateUserId()), SysApprovalApplication::getUpdateUserId, query.getUpdateUserId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getApprovalUserId()), SysApprovalApplication::getApprovalUserId, query.getApprovalUserId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getApprovalUsername()), SysApprovalApplication::getApprovalUsername, query.getApprovalUsername());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRemark()), SysApprovalApplication::getRemark, query.getRemark());

        return queryWrapper;
    }
}
